package com.yanqu.road.server.cmd.tradewar;

import com.yanqu.road.entity.tradewar.CrossTradeWarNotice;
import com.yanqu.road.logic.pb.CrossTradeWarPb;
import com.yanqu.road.pb.cross.tradewar.CrossTradeWarProto;
import com.yanqu.road.server.cmd.CrossCommand;
import com.yanqu.road.server.cmd.CrossUnionCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.manager.tradewar.CrossTradeWarActivity;
import com.yanqu.road.server.manager.tradewar.CrossTradeWarMgr;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.server.protocol.Protocol;

@Cmd(code = Protocol.C_CROSS_TRADE_WAR_ADD_NOTICE, desc = "跨服商战增加公告")
public class CrossTradeWarAddNoticeCmd extends CrossUnionCommand {

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        CrossTradeWarProto.CrossTradeWarNoticeListSyncMsg reqMsg = CrossTradeWarProto.CrossTradeWarNoticeListSyncMsg.parseFrom(packet.getBytes());
        for(CrossTradeWarProto.CrossTradeWarNoticeTempMsg tempMsg : reqMsg.getDataList().getDataListList()) {
            CrossTradeWarNotice notice = CrossTradeWarPb.parseCrossTradeWarNotice(tempMsg);
            if(null != notice) {
                notice.setNoticeTime(System.currentTimeMillis() / 1000);
                notice.setInsertOption();
                CrossTradeWarActivity activity = CrossTradeWarMgr.getActivity(reqMsg.getActivityId(), reqMsg.getGroupId());
                if (activity!=null){
                    activity.addNoticeToList(notice);
                }
            }
        }
        return true;
    }

    @Override
    public void execute(YanQuMessage packet) throws Exception {

    }

    @Override
    public void sendData() {

    }
}
